package com.redfootdev.horseskills;

public class Skill {
	
	private int level;
	private int xp;
	
	public Skill(int level, int xp) {
		this.level = level;
		this.xp = xp;
	}
	
	public Skill() {
		level = xp = 0;
	}
	
	public int getLevel() {
		
		return level;
	}
	
	// Normal routines don't call this. Only admin commands will.
	public void setLevel(int level) {
		this.level = level;
	}
	
	public int getXP() {
		
		return xp;
	}
	// Normal routines don't call this. Only admin commands will.
	public void setXP(int xp) {
		this.xp = xp;
	}
	
	public boolean addXP(int xpAdd) {
		int prevLevel = this.getLevel();
		if (xpAdd < 0) {
			subXP(-xpAdd);
		} else {
			xp += xpAdd;
			while (xp >= (level+1)*100) {
				xp = xp - ((level+1)*100);
				level += 1;
			}
		}
		if(prevLevel < this.getLevel()){
			return true;
		}
		return false;
	}
	
	public void subXP (int xpSub) {
		if (xpSub < 0) {
			addXP(-xpSub);
		} else {
			xp -= xpSub;
			while (xp < 0) {
				xp = xp + ((level)*100);
				level -= 1;
				if(level < 0) {
					level = 0;
					xp = 0;
					return;
				}
			}
		}
	}
	public int getXPTillNextLevel() {
		return 0;
		
	}
	public String toString() {
		return "level: "+ this.getLevel() + "    XP: " + this.getXP();
	}

}